<?php
require_once ('Sys.php');
class DbConnector extends Sys
{	
	var $theQuery;
	static $queries;	
	static $link;	
	
	function DbConnector()
	{	
		parent::Sys();
		$host = parent::getSetting('dbhost');	
		$db = parent::getSetting('dbname');
		$user = parent::getSetting('dbusername');
		$pass = parent::getSetting('dbpassword');		
		
		$this->link = mysql_connect($host, $user, $pass);
		mysql_select_db($db);
		register_shutdown_function(array(&$this, 'close'));		
		return $this;	
	}	
	
	function query($query)
	{	
		$this->theQuery = $query;
		if (parent::$dbg) $this->queries[] = $query;		
		return mysql_query($query, $this->link);	
	}
		
	function numRows($result)
	{
		return mysql_num_rows($result);		
	}
	
	function fetchArray($result)
	{
		return mysql_fetch_array($result);	
	}
	
	function fetchObject($result)
	{
		return mysql_fetch_object($result);	
	}
	
	function close()
	{	
		mysql_close($this->link);	
	}
	
	function Deb_PRNT()
	{		
		parent::Deb_PRNT();
		if (!parent::$dbg) return;		
		echo "<BR/><B>";
		echo 'QUERIES';
		echo "</B><BR/>";
		foreach ($this->queries as $value)
		{
			echo "<BR/>";
			echo $value;
			echo "<BR/>";
		}
		echo "<BR>";		
	}	
}
?>